package com.zzl.spark.recommend

import java.awt.Color

import org.jfree.chart.{ChartFactory, ChartFrame}
import org.jfree.chart.axis._
import org.jfree.chart.labels.StandardCategoryToolTipGenerator
import org.jfree.chart.plot.DatasetRenderingOrder
import org.jfree.chart.renderer.category.LineAndShapeRenderer
import org.jfree.data.category.{DefaultCategoryDataset}

object Chart {
  def plotBarLineChaet(Title: String,xLabel: String,yBarLabel:String,yBarMin:Double,yBarMax:Double,yLineLabel: String,dataBarChaer: DefaultCategoryDataset,dataLineChart: DefaultCategoryDataset): Unit ={

    val chart =ChartFactory.createBarChart(
      "zzl",//Bar标题
      xLabel,
      yBarLabel,
      dataBarChaer,
      org.jfree.chart.plot.PlotOrientation.VERTICAL,//画图方向垂直
      true,//包含 legend
      true,//包含 tooltips
      false//不要显示URL generator
    )
    //获得 plot
    val plot =chart.getCategoryPlot()
    plot.setBackgroundPaint(new Color(0xEE,0x5E,0xFF))
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT)
    plot.setDataset(1,dataLineChart)
    plot.mapDatasetToRangeAxis(1,1)
    //画y轴
    val vn =plot.getRangeAxis()
    vn.setRange(yBarMin,yBarMax)
    vn.setAutoTickUnitSelection(true)
    //画折线y
    val axis2 = new NumberAxis(yLineLabel)
    plot.setRangeAxis(1,axis2)
    val renderer2=new LineAndShapeRenderer()
    renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator())

    plot.setRenderer(1,renderer2)
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD)
    val frame =new ChartFrame(Title,chart)
    frame.setSize(500,500)
    frame.pack()
    frame.setVisible(true)
  }
}
